var engineInfo = {
    'sogou': {
        title: '\u641c\u72d7', engine: 'sogou', // icon: srcurl + '/sogou.png',
        url: 'https://www.sogou.com/tx?ie=utf-8&pid=sogou-site-1f2b8183cd1e469a&query='
    },
    'baidu': {
        title: '\u767e\u5ea6', engine: 'baidu', // icon: srcurl + '/baidu.png',
        url: 'https://www.baidu.com/s?ie=utf8&oe=utf8&tn=98010089_dg&ch=11&wd='
    },
    'bing': {
        title: 'Bing', engine: 'bing', // icon: srcurl + '/bing.png',
        url: 'https://cn.bing.com/search?q='
    },
    'google': {
        title: 'Google', engine: 'google', // icon: srcurl + '/google.ico',
        url: 'https://www.google.com.hk/search?hl=zh-CN&q='
    },
    'csdn':{
        title:'CSDN',
        url:'https://so.csdn.net/so/search?q='
    },
    'cainao':{
        title:'菜鸟',
        url:'https://www.runoob.com/?s='
    }
}

$(".qbsbox-engine-list").mouseover(function(){

}).mouseout(function(){

});

$('.qbsbox-engine-btn').click(
    function () {
        if ($('.qbsbox-engine-list').attr('style')=="display:block"){
            $('.qbsbox-engine-list').attr('style', 'display:none');
        }else {
            $('.qbsbox-engine-list').attr('style', 'display:block');
        }
    }
);
//监听点击事件
document.onmousedown=function(e){
    //当点击位置不在list范围
    if(e.target.offsetParent.className!='qbsbox-engine-list'){
        if ($('.qbsbox-engine-list').attr('style')=="display:block"){
            $('.qbsbox-engine-list').attr('style', 'display:none');
        }
}}

var info = '';
$('.qbsbox-engine ul li').click(
    function () {
        const engine = $(this).attr('data-engine');
        localStorage.setItem('engine', engine);
        info = engineInfo[engine];
        $('.qbsbox-engine-btn').html(info.title);
        $('.qbsbox-engine-list').attr('style', 'display:none');
    });

$('.qbsbox-search-btn').click(
    function () {
        var key = $('.qbsbox-input').val();
        if(key != ''){
            window.open(info.url + $('.qbsbox-input').val())
        }
    });
//输入框绑定keydown事件
$('.qbsbox-input').bind('keydown',function(event){
    if(event.keyCode == '13')
    {
        window.open(info.url + $('.qbsbox-input').val())
    }
});

$(document).ready(
    function () {
        info = engineInfo[localStorage.getItem('engine')];
        $('.qbsbox-engine-btn').html(info.title);
    }
)
